/**
 # # THIS FILE IS PART OF ripap PROJECT
 # #
 # JsonConfig.java - JsonConfig
 # 
 # THIS PROGRAM IS OPENSOURCE SOFTWARE, IS LICENSED UNDER BSD
 # YOU SHOULD HAVE RECEIVED A COPY OF WTFPL LICENSE
 # 
 # Copyright (c) 2018 Ting Fan
 */
package com.cloudkinto.config.json;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
/**
 * @program     : ripap
 * @description : JsonConfig
 * @author      : Ting Fan
 * @company     : 苏州
 * @create      : 2019-05-10 15:44
 **/


/**
 * 处理返回值中的null值
 */
@Configuration
public class JsonConfig {

    @Bean
    public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {

        final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
//        converter.setPrettyPrint(true);
        converter.setDefaultCharset(Charset.forName("UTF-8"));
        ObjectMapper mapper = converter.getObjectMapper();
        SimpleDateFormat smt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        mapper.setDateFormat(smt);
        // 为mapper注册一个带有SerializerModifier的Factory，此modifier主要做的事情为：当序列化类型为array，list、set时，当值为空时，序列化成[]
        mapper.setSerializerFactory(mapper.getSerializerFactory().withSerializerModifier(new MyBeanSerializerModifier()));

        return converter;
    }

}